package com.xs.aifitnessagent.controller;

import com.xs.aifitnessagent.entities.req.UserRegisterReq;
import com.xs.aifitnessagent.entities.req.UserLoginReq;
import com.xs.aifitnessagent.entities.vo.UserVO;
import com.xs.aifitnessagent.resp.ResultData;
import com.xs.aifitnessagent.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lambor
 *
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/list")
    @Operation(summary = "获取用户列表")
    public ResultData<List<UserVO>> getUserList() {
        return ResultData.success(userService.getUserList());
    }

    @GetMapping("/exist")
    @Operation(summary = "获取用户名")
    public ResultData<UserVO> getUserName(String username) {
        return ResultData.success(userService.getUserName(username));
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "获取用户信息")
    public ResultData<UserVO> getUserById(@PathVariable("id") Long id) {
        return userService.getUserById(id);
    }

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public ResultData register(@Validated @RequestBody UserRegisterReq userRegisterReq) {
        return userService.register(userRegisterReq);
    }

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public ResultData<String> login(@RequestBody UserLoginReq userLoginReq) {
        return userService.login(userLoginReq);
    }

    @PostMapping("/logout")
    @Operation(summary = "用户注销登录")
    public ResultData<String> logout() {
        return userService.logout();
    }

    @GetMapping("/getLoginUserInfo")
    @Operation(summary = "获取登录用户信息")
    public ResultData<UserVO> getLoginUserInfo() {
        return userService.getLoginUserInfo();
    }
}
